package com.my.jli.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName LoginInterceptor
 * @Description 登录拦截器
 * @Author MaYu
 * @Date 2022/3/28 10:14
 * @Version 1.0
 **/
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object student = session.getAttribute("student");
        if (student == null ){
            response.sendRedirect("/index");
            return false;
        }
        return true;
    }
}
